<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * 桌号分类
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$store_id=$this->session('store_id');
if(!$store_id){
	exi('请先选择门店！','error');
}
if($_RQ['op']=='list'){
	$params=array('store_id'=>$store_id);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 100;
	$total='';
	$fields=array('id','title','group_id','status','busy','image','scanningnum');
	$list=pdo_getslice('jy_weishop_table',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$return['groups']=pdo_getall('jy_weishop_table_group',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id),array('id','title'),'id');
	$return['busys']=array(
		'0'=>'空闲',
		'1'=>'被占用',
	);
	if($list){
		$hejiorderprice=0;
		$hejiorderprice2=0;
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		if($_RQ['createtime']){
			$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
			$time_range=json_decode($time_range,true);
			$params2['createtime between']=array($time_range['tstart'],$time_range['tend']);
			$return['params']['createtime']=$time_range;
		}
		foreach($list as &$item){
			$params2['tableid']=$item['id'];
			$group = pdo_get('jy_weishop_table_group',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['group_id']),array('id','title'),'id');
			$item['groupname']=$group['title'];
			$item['title']=$item['title'];
			$item['action']='jy_weishop/store.totable//scanning=1&store_id='.$store_id.'&tableid='.$item['id'];
			$item['url']=custom_url('jy_weishop/store.totable//scanning=1&store_id='.$store_id.'&tableid='.$item['id'],true);
			$item['image']=tomedia($item['image']);
			$params2['ispay']=0;
			$item['orderprice'] = pdo_getsum('jy_weishop_order',$params2,'price');
			$params2['ispay']=1;
			$item['orderprice2'] = pdo_getsum('jy_weishop_order',$params2,'price');
			$hejiorderprice +=$item['orderprice'];
			$hejiorderprice2 +=$item['orderprice2'];
		}
	}
	$heji=array('title'=>'合计','orderprice'=>$hejiorderprice,'orderprice2'=>$hejiorderprice2);
	$list[]=$heji;
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'餐桌列表'),
		),
		'list'=>array('data'=>'list','del_one'=>false,'delall'=>false,'edit'=>false,'list'=>array(
			array('name'=>'title','title'=>'餐桌名称','type'=>'string'),
			array('name'=>'groupname','title'=>'餐桌类型','type'=>'string'),
			array('name'=>'orderprice','title'=>'餐桌未支付','type'=>'string'),
			array('name'=>'orderprice2','title'=>'餐桌已支付','type'=>'string'),
		)),
		'search'=>array(
			array('name'=>'title','width'=>15,'title'=>'餐桌名称','type'=>'string'),
			array('name'=>'createtime','width'=>15,'title'=>'下单时间','type'=>'time_range')
		)
	);
	
	$return['htmls']=$htmls;
	exi($return);
}